<template>
    <div>
        <DeHeader>联合登录</DeHeader>
        <section class="container">
            <nav class="tab">
                <a @click="hasAccount = true" href="javascript:;">
                    <i class="iconfont icon-bind" />
                    <span>已有小兔鲜账号，请绑定手机</span>
                </a>
                <a @click="hasAccount = false" href="javascript:;">
                    <i class="iconfont icon-edit" />
                    <span>没有小兔鲜账号，请完善资料</span>
                </a>
            </nav>
            <div class="tab-content" v-if="hasAccount">
                <CallbackBind :nowname="nowname" :headmig="headmig" :openid="openid" @change="loginqiehua">
                </CallbackBind>
            </div>
            <div class="tab-content" v-else>
                <CallbackPatch :openid="openid"></CallbackPatch>
            </div>
        </section>
        <Defooter></Defooter>
    </div>
</template>
<script>
import Defooter from './Defooter.vue';
import DeHeader from './DeHeader.vue';
import CallbackBind from "./CallbackBind.vue"
import CallbackPatch from "./CallbackPatch.vue"
import qc from "qc"
import { loginzhuapi } from "@/utils/api/delogin"
//首页去调用后台的接口 然后检查我当前的账号是否被注册并且绑定过，如果注册并且背绑定，那么存储玩用户的信息后直接跳转到首页，

export default {
    data() {
        return {
            hasAccount: true,//是否有账号
            nowname: '',
            headmig: '',
            openid: "",//登入的唯一表示
        };
    },
    methods: {
        loginqiehua() {
            this.hasAccount = !this.hasAccount
        },
        checkqq() {
            // qc.Login.check()//这个是检检查是否同意qq已经登录了，true为登录
            console.log(qc);
            if (qc.Login.check()) {
                qc.Login.getMe((openid) => {
                    console.log(openid);
                    this.openid = openid
                    // console.log(openid);//openid
                    //调用接口，检查openid是否在本网站上注册
                    loginzhuapi(openid).then(res => {
                        console.log(openid);
                        // console.log(res);
                        // this.$message({ text: '登入成功', type: 'success' })
                        // let { id, account, avatar, nickname, token } = res.result
                        // this.$store.commit('user/setUser', { id, account, avatar, nickname, token })
                        // this.$router.push('/')
                    }).catch(err => {
                        qc.api('get_user_info').success(res => {
                            // console.log(res);
                            this.nowname = res.data.nickname
                            this.headmig = res.data.figureurl
                        })
                    })
                })
            }
        }
    },
    mounted() {
        this.checkqq()
    },
    components: { DeHeader, Defooter, CallbackPatch, CallbackBind }
}
</script>
<style lang="scss">
@import "@/assets/css/variables.scss";

.container {
    padding: 25px 0;
}

.tab {
    background: #fff;
    height: 80px;
    padding-top: 40px;
    font-size: 18px;
    text-align: center;

    a {
        color: #666;
        display: inline-block;
        width: 350px;
        line-height: 40px;
        border-bottom: 2px solid #e4e4e4;

        i {
            font-size: 22px;
            vertical-align: middle;
        }

        span {
            vertical-align: middle;
            margin-left: 4px;
        }

        &.active {
            color: $xtxColor;
            border-color: $xtxColor;
        }
    }
}

.tab-content {
    min-height: 600px;
    background: #fff;
}
</style>